package com.hailiao.beidou.message

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import com.d10ng.app.view.lockScreenOrientation
import com.d10ng.app.view.setStatusBar
import com.d10ng.compose.model.UiViewModelManager
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
import com.hailiao.beidou.message.ui.page.NavGraphs
import com.hailiao.beidou.message.ui.theme.BeidouMessageAndroidTheme
import com.hailiao.beidou.message.utils.NavControllerUtils
import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.animations.rememberAnimatedNavHostEngine

class MainActivity : ComponentActivity() {
    @OptIn(ExperimentalMaterialNavigationApi::class, ExperimentalAnimationApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // 锁定屏幕方向
        lockScreenOrientation()
        // 设置状态栏颜色
        setStatusBar()

        setContent {
            BeidouMessageAndroidTheme {
                val engine = rememberAnimatedNavHostEngine()
                val navController = engine.rememberNavController()
                LaunchedEffect(navController) {
                    NavControllerUtils.register(this@MainActivity, navController)
                }

                DestinationsNavHost(
                    modifier = Modifier
                        .fillMaxSize(),
                    engine = engine,
                    navController = navController,
                    navGraph = NavGraphs.root
                )
            }
            UiViewModelManager.Init(act = this)
        }
    }
}